const fs = require("fs");
const path = require("path");
let dirName = process.argv[2];
const filePath = path.join(__dirname, dirName);

function delDir(filePath) {
    let statObj = fs.statSync(filePath);
    if (statObj.isFile()) {
        fs.unlink(filePath, (err) => {
            if (err) {
                console.log("删除文件失败")
            } else {
                console.log("成功删除文件")
            }
        })
    } else if (statObj.isDirectory()) {
        const files = fs.readdirSync(filePath);
        files.forEach(file => {
            const testPath = `${filePath}/${file}`;
            const stats = fs.statSync(testPath);
            if (stats.isDirectory()) {
                delDir(testPath);
            } else {
                fs.unlinkSync(testPath);
            }
        })
        fs.rmdir(filePath, (err) => {
            if (err) {
                console.log(err)
            }
        });
    }
}

delDir(filePath);